﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Coater.UC
{
    public partial class ucOnOffPanel : UserControl
    {
        private bool _isOn;
        public bool IsOn
        {
            get { return _isOn; }
            set
            {
                _isOn = value;
                pictOnOff.Image = IsOn ?
                    Properties.Resources.plcon :
                    Properties.Resources.plcoff;
            }
        }

        private LeftRightAlignment _ImageAlign = LeftRightAlignment.Left;

        public LeftRightAlignment ImageAlign
        {
            get { return _ImageAlign; }
            set
            {
                _ImageAlign = value;
                this.Refresh();
            }
        }

        private string _Title;
        public string Title
        {
            get { return _Title; }
            set
            {
                _Title = value;
                lbTitle.Text = Title;
            }
        }

        public ucOnOffPanel()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.Selectable, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.UserPaint, true);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            lbTitle.MaximumSize = new Size(this.Width - this.pictOnOff.Width - 15, lbTitle.Height);
            int PictHeight = Convert.ToInt32(this.Size.Height * 0.75);
            int Y = Convert.ToInt32(this.Size.Height * 0.125);
            this.pictOnOff.Size = new Size(PictHeight, PictHeight);
            if (this.ImageAlign == LeftRightAlignment.Left)
            {
                this.pictOnOff.Location = new Point(5, Y);
                this.lbTitle.Location = new Point(10 + PictHeight, (Height - lbTitle.Height) / 2);
            }
            else
            {
                this.pictOnOff.Location = new Point(this.Width - this.pictOnOff.Width - 5, Y);
                this.lbTitle.Location = new Point(5, (Height - lbTitle.Height) / 2);
            }
        }

    }
}
